package 剑指Offer1;

import java.util.Arrays;

public class _48构建乘积数组 {
    public int[] constructArr(int[] a) {
        if(a == null || a.length == 0) return new int[0];
        int[] cj = new int[a.length];
        cj[0] = 1;
        int temp = 1;
        //计算[0,..i-1]的乘积
        for(int i = 1;i<cj.length;i++){
            cj[i] = cj[i-1] * a[i-1];
        }
        //计算[i+1,,,i]的和
        for(int i = a.length - 2;i>=0;i--){
            temp *= a[i+1];
            cj[i] *= temp;
        }
        return cj;
    }

    public static void main(String[] args) {
        int[] cj = new int[4];
        Arrays.fill(cj,1);
        System.out.println(Arrays.toString(cj));
    }
}
